#pragma once
#include "ECS.h"
#include <vector>
#include <string>
#include <map>

namespace ECS
{
	class ComponentDef
	{
	public:
		ComponentDef(MetaClass* cClass, MetaClass* dClass, void* def);

		Component* create();
		bool init(Component* c);

		ComponentDef* clone();

		MetaClass* getComponentClass() const;

		void merge(ComponentDef* other);
	protected:
		void* _def;
		MetaClass* _componentClass;
		MetaClass* _defClass;
	};

	class AssemblyDef
	{
	public:
		AssemblyDef(MetaClass* assemblyClass);

		void addComponent(ComponentDef* def);
		void addOrMerge( ComponentDef * componentDef );

		Assembly* create();

		AssemblyDef* clone();
	protected:
		void init(Assembly* assembly);
		std::vector<ComponentDef*> _components;
		MetaClass* _assemblyClass;
	};

	class Palette
	{
	public:
		void addTemplate(const std::string& name, AssemblyDef* def);
		AssemblyDef* getDef(const std::string& name);
		Assembly* create(const std::string& name);
		template <class T> T* create(const std::string& name) {return (T*)create(name);}
	protected:
		typedef std::map<std::string, AssemblyDef*> PaletteMap;
		PaletteMap _palette;
	};
}